package com.example.lianxi222.register;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.mvvm_base.base.viewmodel.BaseViewModel;
import com.example.mvvm_base.net.Const;
import com.example.mvvm_base.userbean.RegisterEntity;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RegisterViewModel extends BaseViewModel<RegisterRepo> {
    MutableLiveData<RegisterEntity> success=new MutableLiveData<>();
    MutableLiveData<String>  failure=new MutableLiveData<>();


    public RegisterViewModel(@NonNull Application application) {
        super(application);
    }

    public void register(String username,String password,String repeatPassword){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.PARAM_USERNAME,username);
        map.put(Const.PARAM_PASSWORD,password);
        map.put(Const.PARAM_PASSWORD2,repeatPassword);
        String json=new Gson().toJson(map);
        RequestBody body=RequestBody.create(MediaType.parse("application/json;charset=utf-8"),json);
        repo.register(body,success,failure);
    }


    @Override
    protected RegisterRepo createRepo() {
        return new RegisterRepo();
    }
}
